import React, { Fragment, useState, useEffect } from 'react'
import { connect } from 'react-redux'
import { Redirect } from 'react-router-dom'
import { Helmet } from 'react-helmet'
import { getHomeList } from './store/actions'
import styles from './style.css';

function Home(props) {
    useEffect(()=>{
        if(!props.list.length){
            props.getHomeList()
        }
        
    },[])

    if(props.staticContext){
        props.staticContext.css.push(styles._getCss());
    }


    

    // if(!props.isLogin){
    //     return <Redirect to="/login" />
    // }
    return (
        <Fragment>
            <Helmet>
                <title>home页面</title>
            </Helmet>
            <p>{props.name}</p>
            <div className={styles.box} onClick={() => { alert(1) }}>hello home122</div>
            <ul>
                {props.list.map(item=>(
                    <li key={item.name}>{item.name}</li>
                ))}
            </ul>
        </Fragment>

    )
}

const ExportHome = connect(
    state => {
        return {
            isLogin:state.head.isLogin,
            list:state.home.list
        }
    },
    {
        getHomeList
    }
)(Home);



ExportHome.loadData = (store)=>{
    return store.dispatch(getHomeList())
}

export default ExportHome;